<gm:page title="sermitsiaq3" onload="init()">

  <script>
    var Xmap;
    var Xlist;
    var Xitem;
    
    function init() {    
      Xmap = google.mashups.getObjectById("Xmap");
      Xlist = google.mashups.getObjectById("Xlist");
      Xitem = google.mashups.getObjectById("Xitem");
//geocodedelay();
          }
    
function geocodedelay() {
    setTimeout("geocodeContent()", 2000);
}

    function geocodeContent() {
      alert("start map");
      var geocoder = new GClientGeocoder();

      var entry = Xlist.getData().entryAt(0);
      var location = new GPath("address").getValue(entry);
      alert(location);
    
      if (entry) {
        geocoder.getLatLng(location,
          function(point) {
            if (point) {
              //longGPath.setValue(entry, point.lng().toString());
              //latGPath.setValue(entry, point.lat().toString());
              Xlist.getData().addEntry(entry);
            }
            else {
              alert("Geocoder: bad location");
            }
          }
        );
      }
    }
  </script>


  <gm:item id="Xitem" template="XitemTemplate" create="true">
    <gm:handleEvent execute="XitemHandler()" />
  </gm:item>
  
  <p></p>
  
  <table width="100%">
    <tr>
      <td width="350" valign="top">
        <gm:list id="Xlist" data="http://sermitsiaq.gl/rss/map.jsp?ver=105" pagesize="15" template="XlistTemplate">
<gm:handleEvent event="all" execute="geocodeContent();" />            
</gm:list>
      </td>
      <td width="10">
      </td>
      <td valign="top">
        <gm:map id="Xmap" style="border:solid black 2px" control="large" maptypes="true" infotemplate="XmapTemplate">
          <gm:handleEvent src="Xlist" />
        </gm:map>
      </td>
    </tr>
  </table>
  
  <gm:template id="XmapTemplate">
    <div repeat="true">
      <h3><gm:text ref="atom:title" /></h3>
      <gm:textarea ref="atom:summary" />
      (<gm:text ref="gd:lat" />,&nbsp;<gm:text ref="gd:long" />)
    </div>
  </gm:template>
      
  <gm:template id="XlistTemplate">
    <table class="blue-theme" width="100%">
      <thead>
        <th>Location label</th>
        <th width="80">Lat.</th>
        <th width="80">Lng.</th>
        <th width="15">-</th>
      </thead>
      <tr repeat="true">
        <td><gm:text ref="atom:title" /></td>
        <td align="center"><gm:text ref="gd:lat" /></td>
        <td align="center"><gm:text ref="gd:long" /></td>
        <td align="center"><gm:editButtons deleteonly="true" /></td>
      </tr>
      <tfoot>
        <tr>
          <td align="center" colspan="4"><gm:pager /></td>
        </tr>
      </tfoot>
    </table>
  </gm:template>
      
  <gm:template id="XitemTemplate">
    <h2 style="text-align:center">Add a Location!</h2>
    <table width="400" align="center">
      <tbody repeat="true">
        <tr><td align="center"><b>Label</b></td></tr>
        <tr><td align="center"><gm:text ref="atom:title" /></td></tr>
        <tr><td align="center"><b>Address</b></td></tr>
        <tr><td align="center"><gm:text ref="atom:summary" /></td></tr>
        <tr><td align="center"><gm:editButtons /></td></tr>
      </tbody>
    </table>
  </gm:template>

</gm:page>






























